package com.hexiang.web;

import com.hexiang.service.DemoConsumerService;
import com.hexiang.service.GenericDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;

@RestController
public class DemoConsumerController {

    @Autowired
    private DemoConsumerService demoConsumerService;

    @Autowired
    private GenericDemoService genericDemoService;

    @RequestMapping("/sayHello")
    public String sayHello(@RequestParam String name) {
        return demoConsumerService.sayHello(name);
    }

    @RequestMapping("/timeOut")
    public String timeOut(@RequestParam String name) {
        return demoConsumerService.timeOut(name);
    }

    @RequestMapping("/err")
    public String err(@RequestParam String name) {
        return demoConsumerService.asyncCallErr(name);
    }

    @RequestMapping("/asyncTimeOut")
    public DeferredResult<String> asyncTimeOut(@RequestParam String name) {
        return demoConsumerService.asyncTimeOut(name);
    }

    @RequestMapping("/genericSayHello")
    public String genericSayHello(@RequestParam String name) {
        return genericDemoService.sayHello(name);
    }

    @RequestMapping("/asyncSayHello")
    public String asyncSayHello(@RequestParam String name) {
        return demoConsumerService.asyncSayHello(name);
    }

    @RequestMapping("/asyncCallSayHelloAsyncCompletableFuture")
    public DeferredResult<String> asyncCallbackSayHelloCompletableFuture(@RequestParam String name) {
        return demoConsumerService.asyncCallSayHelloAsyncCompletableFuture(name);
    }
    @RequestMapping("/asyncCallSayHelloCompletableFuture")
    public DeferredResult<String> asyncCallSayHelloCompletableFuture(@RequestParam String name) {
        return demoConsumerService.asyncCallSayHelloCompletableFuture(name);
    }

    @RequestMapping("/asyncCallbackSayHello")
    public String asyncCallbackSayHello(@RequestParam String name) {
        return demoConsumerService.asyncCallbackSayHello(name);
    }
}